package gmail.structure;

import java.util.*;

/**
 * Message body of an outgoing mail
 * @author siuying
 * @version 0.2
 */
public class GMSendMailBody {
  private String subject;
  private String msgbody;
  private String draft;
  private String th;
  private String rm;
  private ArrayList to;
  private ArrayList cc;
  private ArrayList bcc;
  private ArrayList attachment;
  private ArrayList attachmentLink;

  public GMSendMailBody() {
    draft = "";
    subject = "";
    msgbody = "";
    rm = "";
    th = "";

    to = new ArrayList();
    cc = new ArrayList();
    bcc = new ArrayList();
    attachment = new ArrayList();
    attachmentLink = new ArrayList();
  }
  
  public boolean equals(GMSendMailBody object){      
    return subject.equals(object.getSubject()) &&
           msgbody.equals(object.getMsgbody()) &&
           rm.equals(object.getRm()) &&
           th.equals(object.getTh()) &&
           draft.equals(object.getDraft());           
  }
  
  /**
   * Textual representation of this mail
   * @return simplify text represetation of this outgoing mail
   * @todo make it a MIME mail message
   */  
  public String toString(){
      return "[ subject=" + subject + 
             ", body=" + msgbody + 
             ", rm=" + rm +
             ", th=" + th +
             ", draft=" + draft +
             " ]"; 
  }
  
  /**
   * Add a to receiver
   * @param address
   */
  public void addTo(String address) {
    to.add(address);
  }
  
  /**
   * Add a cc receiver
   * @param address
   */
  public void addCc(String address) {
    cc.add(address);
  }
  
  /**
   * Add a bcc receiver
   * @param address
   */
  public void addBcc(String address) {
    bcc.add(address);
  }
    
  /**
   * Add an attachment
   * @param file full local path to the attachment file
   */
  public void addAttachment(String file){
      attachment.add(file);
  }
  
  /**
   * Add an attachment from a file existing in gmail
   * @param threadId Thread ID, ID of the thread
   * @param entryId Entry ID, ID of the conversionEntry
   * @param attachmentId Attachment ID of the message, e.g. 0.1, 9.2 ..etc
   */
  public void addAttachmentLink(String threadId, 
                                String entryId, 
                                String attachmentId){
      attachmentLink.add(threadId + "_" + entryId + "_" + attachmentId);
  }
  
  /**
   * Get all attachments in a String array
   * @return String[]
   */
  public String[] getAttachment(){
    return (String[]) attachment.toArray(new String[0]);  
  }
  
  public String[] getAttachmentLink(){
      return (String[]) attachmentLink.toArray(new String[0]);  
  }
  
  public String[] getTo() {
    return (String[]) to.toArray(new String[0]);
  }
  
  public String getToAsString(){
    StringBuffer buf = new StringBuffer();
    for(int i=0; i<to.size(); i++){
        buf.append(to.get(i));        
        if (i<to.size()-1) buf.append(';');
    }
    return buf.toString();    
  }

  public String[] getCc() {
    return (String[]) cc.toArray(new String[0]);
  }
  
  public String getCcAsString(){
    StringBuffer buf = new StringBuffer();
    for(int i=0; i<cc.size(); i++){
        buf.append(cc.get(i));        
        if (i<cc.size()-1) buf.append(';');
    }
    return buf.toString();    
  }
  
  public String[] getBcc() {
    return (String[]) bcc.toArray(new String[0]);
  }
  
  public String getBccAsString(){
    StringBuffer buf = new StringBuffer();
    for(int i=0; i<bcc.size(); i++){
        buf.append(bcc.get(i));        
        if (i<bcc.size()-1) buf.append(';');
    }
    return buf.toString();    
  }
  
  public String getDraft() {
    return draft;
  }

  public String getMsgbody() {
    return msgbody;
  }

  public String getRm() {
    return rm;
  }

  public String getSubject() {
    return subject;
  }

  public String getTh() {
    return th;
  }

  public void setDraft(String draft) {
    this.draft = draft;
  }

  public void setMsgbody(String msgbody) {
    this.msgbody = msgbody;
  }

  public void setRm(String rm) {
    this.rm = rm;
  }

  public void setSubject(String subject) {
    this.subject = subject;
  }

  public void setTh(String th) {
    this.th = th;
  }


}
